package com.huadao.cart_ccs.modle;

import android.content.Context;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.huadao.cart_ccs.base.BaseHttpModel;
import com.huadao.cart_ccs.data.bean.EnvironmentLog;
import com.huadao.cart_ccs.data.source.http.Api;
import com.huadao.cart_ccs.data.source.http.HttpFunction;
import com.huadao.cart_ccs.data.source.http.RetrofitHelper;
import com.huadao.cart_ccs.main.CartApplication;

import java.lang.reflect.Type;
import java.util.Date;

import io.reactivex.Observable;


public class DeviceRuntimeLogModle extends BaseHttpModel{
    private Api api;

    public DeviceRuntimeLogModle(Context context) {
        api=RetrofitHelper.getInstance(context).create(Api.class);
    }

    public Observable<EnvironmentLog> sendEnvironmentLog(Double CO2, Double O2, Double temperature, int state){
        EnvironmentLog environmentLog=new EnvironmentLog();
        environmentLog.setCo2(CO2);
        environmentLog.setO2(O2);
        environmentLog.setTemperature(temperature);
        environmentLog.setState(state);
        environmentLog.setDeviceTime(new Date());
        environmentLog.setProjectId(CartApplication.getInstance().getSystemProjectId());
        environmentLog.setDeviceInfoId(CartApplication.getInstance().getDevId());
        return api.createEnvirmentLog(environmentLog).map(new HttpFunction());
    }

}
